#include "sqlite3.hpp"
#include <iostream>
#include <vector>
#include <cassert>

int select_stu_callback(void* arg, int col_count, char** result, char** fildes_name)
{
    std::vector<std::string>* array = (std::vector<std::string>*) arg;
    array->push_back(result[0]);
    return 0;
}

int main()
{
    SqliteHelper sqlite3("./test.db");
    assert(sqlite3.open());
    // const char* ct = "create table if not exists students(sn int primary key, name varchar(32), age int);";
    // assert(sqlite3.exec(ct));
    // const char* insert_sql = "insert into students values(1, '小明', 17), (2, '小黑', 18), (3, '小红', 16);";
    // assert(sqlite3.exec(insert_sql));
    // const char* update_sql = "update students set name='张晓明' where sn=1;";
    // assert(sqlite3.exec(update_sql));

    const char* query = "select name from students;";
    std::vector<std::string> array;
    assert(sqlite3.exec(query, select_stu_callback, &array));
    for (const auto& name: array)
    {
        std::cout << name << std::endl;
    }
    sqlite3.close();

    return 0;
}